import nyNetwork from "@/api/nyBaseNetwork";
import DZModelPage from "@/model/DZModelPage";
import nyMessageToast from "@/utils/NYMessageToast";
import DZModelCompany from "@/views/公司管理/model/DZModelCompany";
import DZModelAssess from "@/views/测评管理/model/DZModelAssess";
import DZModelReport from "../model/DZModelReport";
import DZModelReportLog from "../model/DZModelReportLog";
import DZModelStaffAssess from "@/views/报告管理/model/DZModelStaffAssess";
import DZModelInvlnReq from "@/views/问卷管理/model/DZModelInvlnReq";
import DZModelStaff from "@/views/员工管理/model/DZModelStaff";

class DZServiceReport {

    company_id: any = null;

    assess_id: any = null;

    staff_id: any = null;

    dateStr: any = null;

    startDate: any = null;

    endDate: any = null;

    reportDate: number = null;

    m_page = new DZModelPage(200);

    m_page_a = new DZModelPage(10);

    list_company: Array<DZModelCompany> = [];

    list_staff: Array<DZModelStaff> = [];

    list_assess: Array<DZModelAssess> = [];

    list_report: Array<DZModelReport> = [];

    list_log: Array<DZModelReportLog> = []

    list_id_page = [];

    list_staff_assess: Array<DZModelStaffAssess> = [];

    net_list_all_company() {
        var arr_data = [];
        nyNetwork.net("全部公司", {}, data => {
            for (const item of data) {
                var company = new DZModelCompany();
                company.id = item.iId ?? '';
                company.name = item.sName ?? '';
                arr_data.push(company);
            }
            this.list_company = arr_data;
        })
    }


    net_list_assess_by_company() {
        var arr_data = [];
        nyNetwork.net("公司测评", { companyId: this.company_id }, data => {
            for (const item of data) {
                var assess = new DZModelAssess();
                assess.id = item.iId ?? '';
                assess.name = item.sName ?? '';
                arr_data.push(assess);
            }
            this.list_assess = arr_data;
        })
    }

    net_list_report() {
        this.list_id_page = [];
        var arr_data = [];
        nyNetwork.net("报告列表", { ...this.m_page, companyId: this.company_id, assessId: this.assess_id, staffId: this.staff_id, date: (this.reportDate ? this.reportDate / 1000 : null) }, data => {
            var reportList = data.list;
            this.m_page.total = data.total;
            for (const item of reportList) {
                var report = new DZModelReportLog();
                report.name = item.sfileName ?? '';
                report.path = item.sfileUrl ?? '';
                report.time = item.createTime ?? '';
                arr_data.push(report);
            }
            this.list_log = arr_data;
        })
    }

    net_down_load(path) {
        nyNetwork.download("下载文件", "?path=" + encodeURIComponent(path));
    }

    net_export_report() {
        if (!this.company_id) {
            nyMessageToast.error("请选择公司")
            return;
        }
        if (!this.assess_id) {
            nyMessageToast.error("请选择报告")
            return;
        }
        if (!this.reportDate) {
            nyMessageToast.error("请选择日期")
            return;
        }
        nyNetwork.download("报告导出", "?reportIdList=" + this.list_id_page.join(","));
    }

    net_list_staff_assess() {
        var arr_data = [];
        nyNetwork.net("量表测评记录", {
            ...this.m_page_a, companyId: this.company_id, assessId: this.assess_id, staffId: this.staff_id,
            startDate: this.startDate, endDate: this.endDate
        }, data => {
            this.m_page_a.total = data.total;
            for (const item of data.list) {
                var req = new DZModelStaffAssess();
                req.companyName = item.companyName ?? '';
                req.departmentName = item.departmentName ?? '';
                req.jobNum = item.jobNum ?? '';
                req.userName = item.userName ?? '';
                req.assessName = item.assessName ?? '';
                req.createTime = item.createTime ?? '';
                arr_data.push(req);
            }
            this.list_staff_assess = arr_data;
        })
    }
    net_export_assess() {
        nyNetwork.down("量表测评记录导出", { companyId: this.company_id, assessId: this.assess_id, startDate: this.startDate, endDate: this.endDate}, '量表测评记录')
    }
}
export default DZServiceReport;